# Contributor: Dennis Przytarski <dennis@przytarski.com>
# Maintainer: Dennis Przytarski <dennis@przytarski.com>
pkgname=firecracker
pkgver=1.1.0
pkgrel=0
pkgdesc="Secure and fast microVMs for serverless computing"
url="https://github.com/firecracker-microvm/firecracker"
arch="aarch64 x86_64"
license="Apache-2.0"
makedepends="rust cargo clang-dev linux-headers"
subpackages="
	$pkgname-seccompiler
	$pkgname-rebase-snap:rebase_snap
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/firecracker-microvm/firecracker/archive/v$pkgver.tar.gz"

_target="$CTARGET"

export CARGO_HOME="$srcdir"/cargo

prepare() {
	default_prepare

	cargo fetch --locked --target "$_target"

	# Change the seccomp filters' names so they get embedded into the binary
	for a in $arch; do
		mv -v resources/seccomp/"$a-unknown-linux-musl.json" resources/seccomp/"$a-alpine-linux-musl.json"
	done
}

build() {
	cargo build \
		--package firecracker \
		--package jailer \
		--package seccompiler \
		--package rebase-snap \
		--target "$_target" \
		--all-features \
		--frozen \
		--release
}

check() {
	# jailer: tests failed testing functionality of cgroups
	# seccompiler: tests failed spawning a thread
	cargo test \
		--package firecracker \
		--package rebase-snap \
		--target "$_target" \
		--frozen

	# Other integration tests need pytest and docker
}

package() {
	install -Dm755 build/cargo_target/"$_target"/release/firecracker \
		-t "$pkgdir"/usr/bin
	install -Dm755 build/cargo_target/"$_target"/release/jailer \
		-t "$pkgdir"/usr/bin
}

seccompiler() {
	pkgdesc="$pkgdesc - seccompiler"
	install -Dm755 "$builddir"/build/cargo_target/"$_target"/release/seccompiler-bin \
		-t "$subpkgdir"/usr/bin
}

rebase_snap() {
	pkgdesc="$pkgdesc - rebasing diff snapshot tool"
	install -Dm755 "$builddir"/build/cargo_target/"$_target"/release/rebase-snap \
		-t "$subpkgdir"/usr/bin
}

sha512sums="
ceb2ed61dac2e11805ec6f8012f76c880a23720ade7849cb18372458f7a39ab9cfc78c82ac6c807faa6a8f8bed8206277d96b8e9445d81bb1af5a000618aa3cb  firecracker-1.1.0.tar.gz
"
